﻿using System;
using System.Reflection;
using System.Collections.Generic;

namespace BizElements.TemplateEngine
{
    /// <summary>
    /// Provides common operations which use advanced reflection features.
    /// </summary>
    static class ReflectionUtil
    {
        /// <summary>Locates the specified class in the given assembly and creates an instance of it using system activator.</summary>
        internal static object CreateInstance(string assemblyFullName, string classFullName)
        {
            Assembly asm = Assembly.Load(assemblyFullName);
            object obj = asm.CreateInstance(classFullName);
            return obj;
        }

        /// <summary>Locates the specified class in the given assembly and creates an instance of it using system activator.</summary>
        internal static object CreateInstance(string assemblyString, string classFullName, object[] ctorArgs)
        {
            Assembly asm = Assembly.Load(assemblyString);
            Type type = asm.GetType(classFullName);
            object obj = Activator.CreateInstance(type, ctorArgs);
            return obj;
        }
    }
}